﻿package mortal.game.view.guild.cellrender
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.skill.panel.render.*;
    import mortal.mvc.core.*;

    public class GuildGodTreeCellRenderer extends GuildCellRenderer
    {
        private var _skillItem:SkillItem;
        private var _txtSkillName:GTextFiled;
        private var _txtSkillLv:GTextFiled;
        private var _apply:GTextFiled;
        private var _getBtn:GLoadingButton;
        private var _money:GTextFiled;

        public function GuildGodTreeCellRenderer()
        {
            return;
        }// end function

        private function onGetBtnClick(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildGetTreeBuff, TreeBuff(data).buffId));
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_5:Array = null;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:Array = null;
            var _loc_9:Array = null;
            var _loc_10:String = null;
            var _loc_11:Boolean = false;
            var _loc_12:String = null;
            super.data = param1;
            var _loc_2:* = param1 as TreeBuff;
            var _loc_3:* = Cache.instance.guild.treeLevel;
            var _loc_4:* = GuildGodTreeConfig.instance.getInfo(_loc_3);
            this._money.textColor = _loc_4 && Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitCoinBind, _loc_4.cost) ? (GlobalStyle.colorHuangUint) : (GlobalStyle.colorHongUint);
            this._money.text = _loc_4 ? (_loc_4.cost.toString()) : ("");
            this._txtSkillName.htmlText = _loc_2.name;
            this._skillItem.source = _loc_2.icon + ".jpg";
            this._txtSkillLv.text = _loc_2.treeType == 1 ? ("Lv" + _loc_2.level + "/10") : ("");
            this._skillItem.toolTipData = "<font color=\'" + GlobalStyle.colorBai + "\'>" + Language.getString(71091) + "</font> <font color=\'" + GlobalStyle.colorLv + "\'>" + _loc_2.level + Language.getArray(71084) + "</font>\n" + "<font color=\'" + GlobalStyle.colorHui + "\'>" + _loc_2.description + "</font> \n";
            if (_loc_2.copyCode && _loc_2.copyCode != "")
            {
                _loc_5 = _loc_2.copyCode.split("#");
                _loc_6 = _loc_5.length;
                _loc_8 = GuildUtil.roleBuff;
                _loc_9 = new Array();
                _loc_7 = 0;
                while (_loc_7 < _loc_6)
                {
                    
                    _loc_9.push(CopyConfig.instance.getCopyInfoByCode(_loc_5[_loc_7]).name);
                    _loc_7++;
                }
                _loc_10 = _loc_9.join(",");
                this._skillItem.toolTipData = this._skillItem.toolTipData + ("<font color=\'" + GlobalStyle.colorHuang + "\'>" + Language.getString(71092) + _loc_10 + "</font>\n");
                this._apply.htmlText = Language.getStringByParam(70520, HTMLUtil.addColor(_loc_10, GlobalStyle.colorLv));
                if (!Cache.instance.copy.copyInfo)
                {
                    this._getBtn.filterEnabled = false;
                }
                else
                {
                    _loc_11 = false;
                    _loc_7 = 0;
                    while (_loc_7 < _loc_6)
                    {
                        
                        if (Cache.instance.copy.copyInfo.code == int(_loc_5[_loc_7]))
                        {
                            _loc_11 = true;
                            break;
                        }
                        _loc_7++;
                    }
                    if (!_loc_11)
                    {
                        this._getBtn.filterEnabled = false;
                    }
                    else
                    {
                        _loc_12 = CopyConfig.instance.getCopyInfoByCode(Cache.instance.copy.copyInfo.code).maps;
                        if (_loc_12 && _loc_12 != "")
                        {
                            if (_loc_12.indexOf(MapFileUtil.mapID.toString()) > -1)
                            {
                                this._getBtn.filterEnabled = _loc_8.indexOf(_loc_2.buffId) == -1 ? (true) : (false);
                            }
                            else
                            {
                                this._getBtn.filterEnabled = false;
                            }
                        }
                        else
                        {
                            this._getBtn.filterEnabled = _loc_8.indexOf(_loc_2.buffId) == -1 ? (true) : (false);
                        }
                    }
                }
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.bg(-20, 78, 280, 1, this, ImagesConst.SplitLine));
            this._skillItem = new SkillItem();
            this._skillItem.x = 20;
            this._skillItem.y = 10;
            this.addChild(this._skillItem);
            this._skillItem.isDragAble = false;
            this._skillItem.isDropAble = false;
            this._skillItem.isThrowAble = false;
            this._skillItem.isShowFreezingEffect = false;
            this._skillItem.isShowLeftTimeEffect = false;
            this._skillItem.isShowToolTip = true;
            this._skillItem.setSize(60, 60);
            this._skillItem.setBg();
            this._skillItem.toolTipMode = SkillItem.TooltipMode_GuildSkill;
            this._apply = UIFactory.gTextField("", 90, 30, 150, 20, this);
            this._getBtn = UIFactory.gLoadingButton(ResFileConst.GuildGodTreeSkillGetBtn, 90, 48, 51, 24, this);
            this._money = UIFactory.gTextField("", 150, 51, 45, 20, this, GlobalStyle.textFormatHuang.right());
            UIFactory.bitmap(ImagesConst.Jinbi_bind, 195, 51, this);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.RIGHT;
            this._txtSkillLv = UIFactory.textField("Lv 1/5", this._skillItem.x, this._skillItem.y + this._skillItem.height - 22, this._skillItem.width, 22, this, _loc_1);
            UIFactory.bg(80, 10, 100, 22, this, ImagesConst.TextBg);
            this._txtSkillName = UIFactory.textField("", 90, 10, 100, 22, this);
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onGetBtnClick);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._skillItem = null;
            this._txtSkillName = null;
            this._txtSkillLv = null;
            this._apply = null;
            this._getBtn = null;
            this._money = null;
            return;
        }// end function

    }
}
